package com.teaphy.coroutinecrawler.flow.operators.transform

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*

fun main() = runBlocking {
    flow {
        var num = 0
        while (true) {
            emit(num)
            num++
            delay(100)
        }
    }.onCompletion { println("onComplete") }
        .transformWhile { ele ->
            repeat(ele) {
                delay(100)
                emit(ele)
            }
            ele < 3
        }.collect {
            println("receive: $it")
        }

    println("Done")
}